package com.example.john.adaptertest;

import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by john on 16/4/17.
 */
public class MyBaseAdapter extends BaseAdapter{
    private List<Item> items;
    private LayoutInflater inflater;

    public MyBaseAdapter(List<Item> items, LayoutInflater inflater) {
        this.items = items;
        this.inflater = inflater;
    }

    @Override
    public int getCount() {
        return items.size();
    }


    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView= inflater.inflate(R.layout.items,null);
        ImageView snap=(ImageView)convertView.findViewById(R.id.snap);
        TextView titel=(TextView)convertView.findViewById(R.id.title);
        TextView content=(TextView)convertView.findViewById(R.id.content);
        //snap.setImageBitmap();


        snap.setImageBitmap(BitmapFactory.decodeByteArray(items.get(position).getSnap(),0,items.get(position).getSnap().length));
        titel.setText(items.get(position).getTitle());
        content.setText(items.get(position).getContent());
        return convertView;
    }
}
